#!/bin/sh

reduces=10

mt=20
rt=5

if [ -d /etc/hadoop/conf.cloudera.mapreduce1 ]; then
    echo "Cloudera hadoop"
    export HADOOP_CONF_DIR=/etc/hadoop/conf.cloudera.mapreduce1
    STREAMJAR=/usr/lib/hadoop-0.20-mapreduce/contrib/streaming/hadoop-streaming.jar
    hdfs dfs -touchz data.txt
    hdfs dfs -rm -r -skipTrash sleep_result
elif [ -d /opt/mapr ]; then
    echo "MapR hadoop"
    STREAMJAR=/opt/mapr/hadoop/hadoop-0.20.2/contrib/streaming/hadoop-0.20.2-dev-streaming.jar
    hadoop dfs -touchz data.txt
    hadoop dfs -rmr -skipTrash sleep_result
else
    echo "HortonWorks hadoop"
    STREAMJAR=/usr/lib/hadoop/contrib/streaming/hadoop-streaming-1.*.jar
    hadoop dfs -touchz data.txt
    hadoop dfs -rmr -skipTrash sleep_result
fi


hadoop jar $STREAMJAR \
    -D mapred.job.name='Sleeping test' \
    -D mapred.map.tasks.speculative.execution=true \
    -D mapred.reduce.tasks.speculative.execution=true \
    -numReduceTasks $reduces \
    -mapper "sleep $mt" \
    -reducer "sleep $rt" \
    -input data.txt -output sleep_result



